#pragma once

namespace Melting
{ 
	/**
		Timer           Since fAppTime is a float, we need to keep the quadword app time 
		                as a LARGE_INTEGER so that we don't lose precision after running
		                for a long time.
	*/
	class Timer
	{    
	public:
		/// CTOR
		Timer( void ) ;

		/// Return the current (absolute) time 
		inline FLOAT				GetAbsoluteTime	( void ) const;
		
		/// Return the current time since app start
		inline FLOAT				GetAppTime		( void ) const;

		/// Return the time elapsed since last update 
		inline FLOAT				GetElapsedTime	( void ) const;
		
		/// Return the current framerate in frame per second
		inline FLOAT				GetFPS			( void ) const;
		
		/// Return current Frame Number -- !!! this WILL overflow !!
		inline UINT32				GetFrameID		( void ) const;

		/// Update the Timer (call it each frame!)
		void						Update			( void );


	protected:

		LARGE_INTEGER	mqwTime;			///< Time
		LARGE_INTEGER	mqwAppTime;			///< Time since app start
		FLOAT			mfSecsPerTick;		///< 

		FLOAT			mfAbsoluteTime;		///< time 
		FLOAT			mfAppTime;			///< time since app start
		FLOAT			mfElapsedTime;		///< time elapsed since last update 

		UINT32			mulNbFrames;		///< Nb 
		FLOAT			mfLastFPSTime;		///< Last time the FPS was updated
		FLOAT			mfFPS;				///< Framerate
	 
	}; 
 

	//-------------------------------------------------------------------------------------
	// Return the current (absolute) time 
	//-------------------------------------------------------------------------------------
	FLOAT Timer::GetAbsoluteTime( void ) const
	{
		return mfAbsoluteTime;
	}

	//-------------------------------------------------------------------------------------
	// Return the current time since app start
	//-------------------------------------------------------------------------------------
	FLOAT Timer::GetAppTime( void ) const
	{
		return mfAppTime;
	}

	//-------------------------------------------------------------------------------------
	// Return the time elapsed since last update
	//-------------------------------------------------------------------------------------
	FLOAT Timer::GetElapsedTime( void ) const
	{
		return mfElapsedTime;
	}
	
	//-------------------------------------------------------------------------------------
	// Return the current framerate in frame per second
	//-------------------------------------------------------------------------------------
	FLOAT Timer::GetFPS( void ) const
	{
		return mfFPS;
	}
	
	//-------------------------------------------------------------------------------------
	// Return current Frame Number -- !!! this WILL overflow !!
	//-------------------------------------------------------------------------------------
	UINT32 Timer::GetFrameID( void ) const
	{
		return mulNbFrames;
	} 
}

